package com.talent.web.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.talent.web.mapper.TlFileMapper;
import com.talent.web.model.entity.TlFile;
import com.talent.web.model.query.FileQuery;
import com.talent.web.service.ITlFileService;
import org.springframework.stereotype.Service;

/**
 * @ClassName：TlFileServiceImpl
 * @Author: hszhou
 * @Date: 2025/3/4 9:28
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Service
public class TlFileServiceImpl extends ServiceImpl<TlFileMapper, TlFile> implements ITlFileService {
    @Override
    public IPage<TlFile> page(int current, int pageSize, FileQuery query) {
        IPage<TlFile> page = new Page(current,pageSize);
        LambdaQueryWrapper<TlFile> queryWrapper = new LambdaQueryWrapper<>();
        if(StrUtil.isNotEmpty(query.getName())){
            queryWrapper.eq(TlFile::getFileName,query.getName());
        }
        if(StrUtil.isNotEmpty(query.getCode())){
       //     queryWrapper.eq(TlFile::getCode,query.getCode());
        }
        return this.page(page,queryWrapper);
    }

    @Override
    public boolean isExitsFile(String identifier, String bucketName) {
        Long count = this.baseMapper.selectCount(Wrappers.<TlFile>lambdaQuery()
                .eq(TlFile::getIdentifier, identifier)
                .eq(TlFile::getBucketName, bucketName));
        return count > 0;

    }

    @Override
    public TlFile selectFileByIdentifier(String identifier) {
    return this.baseMapper.selectOne(Wrappers.<TlFile>lambdaQuery()
                .eq(TlFile::getIdentifier, identifier)
                );
    }
}
